/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.cnbm.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cnbm.common.utils.PageUtils;
import com.cnbm.common.utils.Query;
import com.cnbm.modules.sys.dao.SysLogDao;
import com.cnbm.modules.sys.entity.SysLogEntity;
import com.cnbm.modules.sys.service.SysLogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author weihongyang
 * @Date 2020/8/10 15:46
 * @Version 1.0
 */
@Service("sysLogService")
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLogEntity> implements SysLogService {

    @Autowired
    private SysLogDao sysLogDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String)params.get("key");

        IPage<SysLogEntity> page = this.page(
            new Query<SysLogEntity>().getPage(params),
            new QueryWrapper<SysLogEntity>().like(StringUtils.isNotBlank(key),"username", key)
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils listByTerm(Map<String, Object> params) {
        Page<SysLogEntity> page = new Page<>();
        page.setCurrent(Integer.valueOf(params.get("page").toString()));
        page.setSize(Integer.valueOf(params.get("limit").toString()));
        List<SysLogEntity> list = sysLogDao.listByTerm(page,params);
        page.setRecords(list);
        return new PageUtils(page);
    }

    @Override
    public PageUtils operationList() {
        Page<SysLogEntity> page = new Page<>();
        page.setCurrent(1);
        page.setSize(9999);
        List<SysLogEntity> list = sysLogDao.operationList(page);
        page.setRecords(list);
        return new PageUtils(page);
    }
}
